package com.whf.android.jar.net.rx;

import com.whf.android.jar.constants.BaseEntries;

import java.util.List;
import java.util.WeakHashMap;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.HeaderMap;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

/**
 * Created
 *
 * @author 傅令杰
 * @version 2017/4/2
 */
public interface RxRestService<T> {
    /***
     * get
     * @param url：
     * @param params：
     * @return json
     */
    @GET
    Observable<BaseEntries<T>> get(@Url String url, @QueryMap WeakHashMap<String, Object> params);

    /***
     * post
     * @param url：
     * @param params：
     * @return json
     */
    @FormUrlEncoded
    @POST
    Observable<BaseEntries<T>> post(@HeaderMap WeakHashMap<String, Object> lang,
                                    @Url String url, @FieldMap WeakHashMap<String, Object> params);

    /***
     * postRaw
     * @param url：
     * @param body：
     * @return json
     */
    @POST
    Observable<BaseEntries<T>> postRaw(@HeaderMap WeakHashMap<String, Object> lang,
                                       @Url String url, @Body RequestBody body);

    /***
     * put
     * @param url：
     * @param params：
     * @return json
     */
    @FormUrlEncoded
    @PUT
    Observable<BaseEntries<T>> put(@HeaderMap WeakHashMap<String, Object> lang,
                                   @Url String url, @FieldMap WeakHashMap<String, Object> params);

    /***
     * putRaw
     * @param url：
     * @param body：
     * @return json
     */
    @PUT
    Observable<BaseEntries<T>> putRaw(@HeaderMap WeakHashMap<String, Object> lang,
                                      @Url String url, @Body RequestBody body);

    /***
     * delete
     * @param url：
     * @param params：
     * @return json
     */
    @DELETE
    Observable<BaseEntries<T>> delete(@Url String url, @QueryMap WeakHashMap<String, Object> params);

    /***
     * download
     * @param url：
     * @param params：
     * @return json
     */
    @Streaming
    @GET
    Observable<ResponseBody> download(@HeaderMap WeakHashMap<String, Object> lang,
                                      @Url String url, @QueryMap WeakHashMap<String, Object> params);

    /***
     * upload
     * @param url：
     * @param file：
     * @return json
     */
    @Multipart
    @POST
    Observable<BaseEntries<T>> upload(@HeaderMap WeakHashMap<String, Object> lang,
                                      @Url String url, @Part MultipartBody.Part file);

    /***
     * upload
     * @param url：
     * @param parts：
     * @return json
     */
    @Multipart
    @POST
    Observable<BaseEntries<T>> upload(@HeaderMap WeakHashMap<String, Object> lang,
                                      @Url String url, @Part List<MultipartBody.Part> parts);

}
